<!-- 到访详情 --> 
<template>
  <div class="visitDetail">
    <el-card class="card">
      <div class="top_nav" v-if="pageType === 'details'">
        <div>
          <p @click="pageType = 'edit'">
            <i class="iconfont icon-bianji1"></i>
            编辑
          </p>
        </div>
      </div>
      <div class="line" v-if="pageType === 'details'"></div>
      <div class="header_info">
        <div class="header_info_img">
          <img :src="formData.headimgurl" alt="加载失败">
        </div>
        <div class="header_info_config" style="padding-left: 14px;">
          <p>到访记录</p>
          <p v-if="pageType !== 'create'">{{ formData.name }}</p>
          <p v-if="pageType === 'create'">新增到访记录</p>
        </div>
        <div class="save_info" v-if="pageType !== 'details'">
          <!-- <p>
            <i class="iconfont icon-baocun"></i>
            保存
          </p> -->
          <p @click="handleSubmit('visitManage')">
            <!-- <i class="iconfont icon-close"></i> -->
            保存
          </p>
          <p @click="goToURL('visitManage')">
            <!-- <i class="iconfont icon-close"></i> -->
            关闭
          </p>
        </div>
      </div>
      <!-- 查看到访详情页面 -->
      <div class="niche_info" v-if="pageType === 'details'">
        <el-form ref="form" :model="formData" :rules="rules" label-width="120px">
          <p class="niche_title">基本信息</p>
          <div class="niche_content">
            <el-form-item label="名称：">
              <el-input v-model="formData.title" style="width: 218px;" disabled></el-input>
            </el-form-item>
            <el-form-item label="潜在顾客：">
              <el-input v-model="formData.name" style="width: 218px;" disabled></el-input>
            </el-form-item>
            <el-form-item label="预约者：" v-if="formData.username">
              <el-input v-model="formData.username" style="width: 218px;" disabled></el-input>
            </el-form-item>
            <el-form-item label="性别：">
              <el-select v-model="formData.sex" placeholder="请选择" disabled>
                <el-option
                  v-for="item in sexList"
                  :key="item.value"
                  :label="item.label"
                  :value="parseInt(item.value)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="预约中心：">
              <el-select v-model="formData.branch_id" placeholder="请选择" disabled>
                <el-option
                  v-for="item in centerList"
                  :key="item.id"
                  :label="item.name"
                  :value="parseInt(item.id)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="预约时间：">
              <el-date-picker
                v-model="formData.visit_time"
                type="datetime"
                placeholder="选择时间"
                disabled>
              </el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="预约编号：">
              <el-input v-model="formData.appointNo" style="width: 218px;" disabled></el-input>
            </el-form-item> -->
            <el-form-item label="到访时间：">
              <el-date-picker
                v-model="formData.visit_time"
                type="datetime"
                placeholder="选择时间"
                disabled>
              </el-date-picker>
            </el-form-item>
            <el-form-item label="到访属性：">
              <el-select v-model="formData.property" placeholder="请选择" disabled>
                <el-option
                  v-for="item in visitProperty"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <!-- <link-details :moduleData="moduleData" :formData="formData" @changeFormData="changeFormData"></link-details> -->
          <p class="niche_title">备注</p>
          <div class="niche_content">
            <div id="remark">
            </div>
          </div>
        </el-form>
      </div>
      <!-- 新增到访详情页面 -->
      <div class="niche_info" v-if="pageType === 'create'">
        <el-form ref="form" :model="formData" :rules="rules" label-width="120px">
          <p class="niche_title">基本信息</p>
          <div class="niche_content">
            <el-form-item label="名称：">
              <el-input v-model="formData.no" style="width: 218px;" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="潜在顾客：">
              <el-select v-model="formData.sex" placeholder="请选择">
                <el-option
                  v-for="item in sexList"
                  :key="item.value"
                  :label="item.label"
                  :value="parseInt(item.value)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="预约者：">
              <el-input v-model="formData.no" style="width: 218px;" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="性别：">
              <el-select v-model="formData.sex" placeholder="请选择">
                <el-option
                  v-for="item in sexList"
                  :key="item.value"
                  :label="item.label"
                  :value="parseInt(item.value)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="预约中心：">
              <el-select v-model="formData.sex" placeholder="请选择">
                <el-option
                  v-for="item in sexList"
                  :key="item.value"
                  :label="item.label"
                  :value="parseInt(item.value)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="预约时间：">
              <el-date-picker
                v-model="formData.sex"
                type="datetime"
                placeholder="选择时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="预约编号：">
              <el-input v-model="formData.no" style="width: 218px;" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="预约类型：">
              <el-select v-model="formData.sex" placeholder="请选择">
                <el-option
                  v-for="item in sexList"
                  :key="item.value"
                  :label="item.label"
                  :value="parseInt(item.value)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="到访时间：">
              <el-date-picker
                v-model="formData.sex"
                type="datetime"
                placeholder="选择时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="到访状态：">
              <el-select v-model="formData.sex" placeholder="请选择">
                <el-option
                  v-for="item in sexList"
                  :key="item.value"
                  :label="item.label"
                  :value="parseInt(item.value)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="预约地点：">
              <el-input v-model="formData.no" style="width: 218px;"></el-input>
            </el-form-item>
          </div>
          <p class="niche_title">备注</p>
          <div class="niche_content">
            <link-editor></link-editor>
          </div>
        </el-form>
      </div>
      <!-- 编辑预约详情页面 -->
      <div class="niche_info" v-if="pageType === 'edit'">
        <el-form ref="form" :model="formData" :rules="rules" label-width="120px">
          <p class="niche_title">基本信息</p>
          <div class="niche_content">
            <el-form-item label="名称：">
              <el-input v-model="formData.title" style="width: 218px;" disabled></el-input>
            </el-form-item>
            <el-form-item label="潜在顾客：">
              <el-input v-model="formData.name" style="width: 218px;" disabled></el-input>
            </el-form-item>
            <el-form-item label="预约者：" v-if="formData.username">
              <el-input v-model="formData.username" style="width: 218px;" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="性别：">
              <el-select v-model="formData.sex" placeholder="请选择">
                <el-option
                  v-for="item in sexList"
                  :key="item.value"
                  :label="item.label"
                  :value="parseInt(item.value)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="预约中心：">
              <el-select v-model="formData.branch_id" placeholder="请选择">
                <el-option
                  v-for="item in centerList"
                  :key="item.id"
                  :label="item.name"
                  :value="parseInt(item.id)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="预约时间：">
              <el-date-picker
                v-model="formData.visit_time"
                type="datetime"
                placeholder="选择时间">
              </el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="预约编号：">
              <el-input v-model="formData.appointNo" style="width: 218px;" disabled></el-input>
            </el-form-item> -->
            <el-form-item label="到访时间：">
              <el-date-picker
                v-model="formData.visit_time"
                type="datetime"
                placeholder="选择时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="到访属性：">
              <el-select v-model="formData.property" placeholder="请选择">
                <el-option
                  v-for="item in visitProperty"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <!-- <link-details :moduleData="moduleData" :formData="formData" @changeFormData="changeFormData"></link-details> -->
          <p class="niche_title">备注</p>
          <el-form-item>
            <div class="niche_content" :model="formData.remark">
              <link-editor @editor-info="getEditorInfo" :editorInfo="formData.remark"></link-editor>
            </div>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
import http from '@/api/visit'
import globalHttp from '@/api/global'
import editor from '@/components/editor'
import details from '@/components/details'
import {detailsMinin} from '@/mixin'
import {formatDate, formatArray} from '@/utils'
export default {
  name: 'visitDetail',
  mixins: [detailsMinin],
  components: {
    linkEditor: editor,
    linkDetails: details
  },
  data () {
    return {
      http: http,
      globalHttp: globalHttp,
      rules: {},
      followRules: {},
      formData: {},
      followFormData: {},
      sexList: [],
      pageType: null,
      fileList: [],
      pageParams: null,
      pageType: null,
      centerList: [],
      visitProperty: []
    }
  },
  methods: {
    getEditorInfo (data) {
      this.formData.remark = data
    },
    goToURL (name, query) {
      this.$router.push({name, query})
    },
    closeNiche () {
      this.closeModal = true
      this.noReason = false
    },
    handlePreview () {
    },
    handleRemove () {
    },
     // 预约属性
    getVisitProperty () {
      let varname = 'visit_property'
      globalHttp.getWebConfig({varname}).then(res => {
        this.visitProperty = res.data
      })
    },
    init () {
      let userData = JSON.parse(sessionStorage.getItem('user'))
      let basicConfig = JSON.parse(sessionStorage.getItem('basicConfig'));
      this.sexList = formatArray(basicConfig.sex)
      this.formData.center_id = userData.center_id
      this.formData.username = userData.username
      this.getPageParams('visitDetailParams', () => {
        this.getCommonModuleFields('student')
      })
    }
  },
  created () {
    this.init()
    if (this.pageType !== 'create') {
      let id = this.pageParams.id
      http.getContentDetail({id}).then(res => {
        this.formData = res.data
      })
    }
    let userData = JSON.parse(sessionStorage.getItem('user'))
    let id = userData.center_id
    globalHttp.getCenterList({id}).then(res => {
      this.centerList = res.data
      console.log(this.centerList)
    })
    this.getVisitProperty()
  },
  mounted () {
    if (this.pageParams.id) {
      let id = this.pageParams.id
      this.http.getContentDetail({id}).then(res => {
        this.formData = res.data
        showRemark(this.formData.remark)
      })
    }
    this.formData.remark = this.editorContent
  }
}
function showRemark (html) {
  var remark = document.getElementById('remark')
  remark.innerHTML = html
  var imgs = remark.getElementsByTagName('img')
  for (let img of imgs) {
    img.style.width = '100px'
  }
}
</script>

<style lang="scss" scoped>
  .visitDetail {
    padding: 10px;
    .card {
      .header_info {
        position: relative;
        padding: 26px 0 45px 34px;
        display: flex;
        &_img {
          width: 47px;
          height: 47px;
          overflow: hidden;
          border-radius: 50%;
          img {
            width: 47px;
            height: 47px;
          }
        }
        &_config {
          padding-left: 26px;
          padding-right: 26px;
          // border-right: 1px solid #bfbfbf;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          &:last-of-type {
            border-right: none;
          }
          p {
            &:nth-of-type(1) {
              font-size: 14px;
              color: #565656;
            }
            &:nth-of-type(2) {
              font-size: 20px;
              color: #333;
              font-weight: 600;
            }
          }
        }
        .save_info {
          display: flex;
          position: absolute;
          right: 40px;
          top: 36px;
          p {
            margin-left: 20px;
            border-radius: 5px;
            cursor: pointer;
            &:nth-of-type(1) {
              color: #1799EB;
              padding: 9px 22px;
              background: #E5F4FF;
            }
            &:nth-of-type(2) {
              color: #1799EB;
              padding: 9px 22px;
              background: #E5F4FF;
            }
            // &:nth-of-type(2) {
            //   color: white;
            //   padding: 9px 12px;
            //   background: linear-gradient(to right, #17B5EB, #1796EB)
            // }
          }
        }
      }
      .niche_info {
        .niche_title {
            width: 100%;
            line-height: 41px;
            background: #F5F5F5;
            padding-left: 24px;
            color: #333;
            font-size: 20px;
            font-weight: 600;
        }
        .niche_content {
          padding: 40px 0 44px 24px;
          padding-top: 40px;
          display: flex;
          flex-wrap: wrap;
          /deep/ .el-form-item {
            //   width: 25%;
              font-weight: 600;
          }
          // ul {
          //   &:nth-of-type(1) {
          //     margin: 0;
          //   }
          //   &:last-of-type {
          //     margin: 30px 0 0 0;
          //   }
          //   li {
          //     width: 25%;
          //     font-size: 16px;
          //     font-weight: 600;
          //     /deep/ .el-form-item {
          //       margin: 0;
          //     }
          //     span {
          //         font-weight: 400;
          //     }
          //   }
          //   display: flex;
          //   list-style: none;
          //   margin: 30px 0;
          // }
        }
      }
      .top_nav {
        padding-left: 34px;
        div {
          display: flex;
          padding: 25px 0;
          p {
            margin-right: 20px;
            color: #565656;
            font-size: 16px;
            cursor: pointer;
            &:hover {
                color: #1796EB;
            }
          }
        }
      }
      .line {
        height: 1px;
        width: 100%;
        background: #bfbfbf;
      }
    }
    .contract_pic {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      img {
        width: 191px;
        height: 171px;
      }
    }
    .btn {
      margin-top: 30px;
      width: 100%;
      display: flex;
      justify-content: center;
      /deep/ .el-button {
        width: 214px;
      }
    }
    .follow_customer {
      display: flex;
      width: 100%;
      .follow_form {
        width: 100%;
        /deep/ .el-upload-list {
          display: flex;
          li {
            width: 20%;
            margin-right: 10px;
            .el-upload-list__item-name {
              display: none;
            }
          }
        }
        .el-textarea {
          width: 491px;
        }
        .el-input {
          width: 179px;
        }
        .el-select {
          width: 179px;
        }
      }
    }
  }
</style>